package cn.mystyle.account.server.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;

import cn.mystyle.account.server.dao.RecordDao;
import cn.mystyle.common.constant.ResultCodeJson;
import cn.mystyle.common.response.ListResponse;
import cn.mystyle.model.account.Record;

@Service
public class RecordService
{
    @Autowired
    private RecordDao recordDao;
    
    public JSONObject insertRecord(Record record)
    {
        int rtcode = recordDao.insertRecord(record);
        if (rtcode > 0)
        {
            return ResultCodeJson.getSuccess();
        }
        return ResultCodeJson.get500();
    }
    
    /** 
     * 查询记录
     * @param record 查询条件
     * @return JSONObject
     * @see [类、类#方法、类#成员]
     */
    public JSONObject queryRecord(Record record)
    {
        List<Record> records = recordDao.findRecord(record);
        int total = recordDao.findRecordTotal(record);
        
        ListResponse<Record> listRecord = new ListResponse<Record>();
        listRecord.setResult(records);
        listRecord.setTotal(total);
        
        return JSONObject.parseObject(listRecord.toString());
    }
    
    /** 
     * 删除记录
     * @param record
     * @return JSONObject
     * @see [类、类#方法、类#成员]
     */
    public JSONObject deleteRecord(Record record)
    {
        int rtcode = recordDao.deleteRecord(record);
        if (rtcode > 0)
        {
            return ResultCodeJson.getSuccess();
        }
        return ResultCodeJson.get500();
    }
    
    /** 
     * 更新记录
     * @param record
     * @return JSONObject
     * @see [类、类#方法、类#成员]
     */
    public JSONObject updateRecord(Record record)
    {
        int rtcode = recordDao.updateRecord(record);
        if (rtcode > 0)
        {
            return ResultCodeJson.getSuccess();
        }
        return ResultCodeJson.get500();
    }
}
